package com.lucas;

import com.lucas.service.HelloService;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.Set;
import java.util.concurrent.*;
import java.util.stream.IntStream;

public class customMain {
    public static void main(String[] args) throws IOException {
//        ExtensionLoader<HelloService> extension = ExtensionLoader.getExtensionLoader(HelloService.class);
//        Set<String> supportedExtensions = extension.getSupportedExtensions();
//        System.out.println("==========开始===========");
//        for (String supportedExtension : supportedExtensions) {
//            System.out.println("supportedExtension==="+supportedExtension);
//            extension.getExtension(supportedExtension).sayHello("我讲hello 你讲嗨佬");
//        }


        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        DubboRpcCustomService dubboService = context.getBean(DubboRpcCustomService.class);
        System.out.println("please system in the str");
        ThreadPoolExecutor service = new ThreadPoolExecutor(10,20,60,TimeUnit.SECONDS,new LinkedBlockingDeque<>());
        while (true) {
            ThreadLocalRandom random = ThreadLocalRandom.current();
            int read = random.nextInt(3);
            service.submit(new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    String key;
                    if(read==1){
                        key= "human";
                    }else if(read == 3){
                        key = "dog";
                    }else{
                        key = "plant";
                    }
                    String hello = dubboService.rpcTestMethod(key);
                    System.out.println("result :" + hello);
                    return hello;
                }
                });
            }
        }

    @Configuration
    @EnableDubbo(scanBasePackages = "com.lucas")
    @PropertySource("classpath:/dubbo-custom.properties")
    @ComponentScan(value = {"com.lucas"})
    static class ConsumerConfiguration {

    }

    }


